import {fromJS} from "immutable";
import {
    change_banner_index, project_update_tag,
    SAVE_BANNER_DATA, save_project_data, update_article_choice, update_article_data,
    update_banner_timer,
    update_search_data, update_tag,
    update_website_data
} from "../contants";

const defaultState = fromJS({
    bannerList: [],     //轮播图列表
    lastIndex: -1,      //轮播图上一个展示的图片
    currentIndex: 0,    //当前展示的图片
    bannerTimer: null,   //轮播图定时器
    webSiteList: [],      //常用网站
    searchList: [],        //大家都在搜
    titleIndex: 0, //选择文章的标题 0 最新博文 1 项目
    homePageIndex: 0,    //文章页码
    homePageList: [],
    shouldUpdate: true,    //是否应该更新
    projectList: [],    //文章列表数据
    projectIndex: 0,    //文章页码
    projectTag: true,  //是否可以更新
});

export default (status = defaultState, action) => {

    switch (action.type) {
        case SAVE_BANNER_DATA:
            //务必这样返回 不然不会执行数据的改变的
            return status.set("bannerList", fromJS(action.data));

        case update_banner_timer:
            return status.set("bannerTimer", fromJS(action.bannerTimer));

        case change_banner_index:
            return status.merge({
                lastIndex: action.lastIndex,
                currentIndex: action.currentIndex
            });

        case update_website_data:
            return status.set("webSiteList", fromJS(action.data));

        case update_search_data:
            return status.set("searchList", fromJS(action.data));

        case update_article_data:

            return status.merge({
                homePageIndex: action.index,
                homePageList: status.get("homePageList").concat(fromJS(action.data))
            });

        case update_tag:
            return status.set("bool", action.bool);

        case update_article_choice:
            return status.set("titleIndex", action.titleIndex);

        case save_project_data:
            return status.merge({
                projectIndex: action.index,
                projectList: status.get("projectList").concat(fromJS(action.data))
            });
        case project_update_tag:
            return status.set("projectTag", action.bool);

        default:
            return status;
    }

};